package com.vonchenchen.android_renderer;

import android.os.Bundle;
import android.view.SurfaceView;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.vonchenchen.renderer.CameraEvaluator;

/**
 * Created by  on 2021/1/28.
 */
public class CaptureActivity extends AppCompatActivity {

    private SurfaceView mCaptureView;
    private CameraEvaluator mCameraEvaluator;
    private Button mCaptureBtn;
    private boolean mCaptureStart;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_capture);

        mCaptureView = findViewById(R.id.sv_capture);
        mCaptureBtn = findViewById(R.id.btn_capture);

        mCaptureBtn.setOnClickListener((v)->{
            if(mCaptureStart){
                mCaptureBtn.setText("capture start");
                mCameraEvaluator.stopPreview();
            }else {
                mCaptureBtn.setText("capture stop");
                mCameraEvaluator.startPreview();
            }
            mCaptureStart = !mCaptureStart;
        });

        findViewById(R.id.btn_alloc).setOnClickListener((v)->{

            if(mCameraEvaluator == null) {
                mCameraEvaluator = new CameraEvaluator();
            }
        });

        findViewById(R.id.btn_dealloc).setOnClickListener((v)->{

            if(mCameraEvaluator != null) {
                mCameraEvaluator.release();
                mCameraEvaluator = null;
            }
        });
    }
}
